package com.zx.servicelearn.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.util.Log;

import com.zx.servicelearn.model.Book;
import com.zx.servicelearn.myaidl.IBookManager2;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by zhoux on 2018/3/2.
 * 注释：
 */

public class IPCService3_MYAIDL extends Service {
    String TAG = "IPCService3_MYAIDL";
    private CopyOnWriteArrayList<Book> list = new CopyOnWriteArrayList<>();//支持并发读写的list


    Binder mIBookManager2 = new IBookManager2.BookManager2Stub() {

        @Override
        public void add(Book book) throws RemoteException {
            Log.e(TAG, "add");
            list.add(book);
        }

        @Override
        public List<Book> getList() throws RemoteException {
            Log.e(TAG, "getList");
            return list;
        }

    };

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mIBookManager2;
    }
}
